using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace PEM
{
    internal abstract class ViewModelBase: INotifyPropertyChanged, IDisposable
    {
        #region Finalizer

        ~ViewModelBase()
        {
            Dispose(false);
        }

        #endregion // Finalizer

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            GC.SuppressFinalize(this);
            Dispose(true);
        }

        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    DisposeManaged();
                }

                DisposeNative();

                _disposed = true;
            }
        }

        protected virtual void DisposeManaged()
        {
        }

        protected virtual void DisposeNative()
        {
        }

        #endregion

        #region Fields

        protected bool _disposed;

        #endregion // Fields
    }
}
